<?php

namespace app\api\controller;

use app\api\library\Tools;
use app\common\controller\Api;
use think\App;
use think\facade\Request;

/**
 * 首页接口.
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    protected $tools = null;

    public function __construct(App $app, Tools $tools)
    {
        parent::__construct($app);
        $this->tools = $tools;
    }

    const BACK = [
        '2101' => '<Response> 
  <resultCode>0</resultCode>  
  <resultMsg>建卡成功</resultMsg>  
  <patientId>1234567890</patientId>  
  <cardNo>411081199101010101</cardNo> 
</Response>',
        '2102' => '<Response> 
  <resultCode>0</resultCode>  
  <resultMsg>操作成功</resultMsg>  
  <Item> 
    <patientId>705400000011</patientId>  
    <cardNo>4110811991</cardNo>  
    <patientName>测试</patientName>  
    <idNo>411081199101252159</idNo>  
    <sex>1</sex>  
    <age>27</age>  
    <birthday>1991-01-25</birthday>  
    <phone>13838313420</phone>  
    <address>测试地址</address>  
    <guardianName>1</guardianName>  
    <guardianidNo>1</guardianidNo>  
    <guardianPhone>1</guardianPhone>  
    <cardType>1701</cardType>  
  </Item> 
</Response>',

        '4201' => '<Response> 
  <resultCode>0</resultCode>  
  <resultMsg>操作成功</resultMsg>  
  <Item> 
    <cardNo>0000871268</cardNo>  
    <patientId>00028783</patientId>  
<patientName>测试</patientName>
<clinicNo>34234234</clinicNo>  
<deptCode>0002 </deptCode>
    <deptName>初始科室</deptName>  
    <admDate>2020-03-12 12:32:12</admDate>
    <doctorCode>023212</doctorCode>  
<doctorName>测试医生</doctorName> 
  </Item>
</Response>',
        '4202' => '<Response> 
  <resultCode>0</resultCode>  
  <resultMsg>操作成功</resultMsg>  
  <data> 
    
  </data> 
</Response>',
        '4204' => '<Response> 
  <resultCode>0</resultCode>  
  <resultMsg>操作成功</resultMsg> 
  <receiptId>123123123123</receiptId>
  <guideInfo>导诊信息</ guideInfo>
</Response>',
    ];


    /**
     * 首页.
     */
    public function index()
    {


        $re = $this->tools->params();


        if (empty($re['method'])) return 'a';
        $method = $re['method'];
        if (empty(self::BACK[$method])) return 'b';
        return $this->tools->xmlReturn1(self::BACK[$method]);


        //      return $this->tools->xmlReturn(json_decode($data,true));
//        return $this->tools->xmlReturn1($data);
//        $this->success('请求成功',[Request::instance()->request()]);
    }


    public function json()
    {
        $xml = file_get_contents("php://input");
        return $this->tools->xmlToJson($xml);
    }
}
